﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication16
{
    public partial class Form1 : Form
    {
        HtmlDocument htmlDoc;
        TextBox tbsearchByName = new TextBox();
        Button bttest = new Button();
        public Form1()
        {
            InitializeComponent();
            monthCalendar1.Visible = false;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {
            string day = monthCalendar1.SelectionStart.Day.ToString();
            string month = monthCalendar1.SelectionStart.Month.ToString();
            string year = monthCalendar1.SelectionStart.Year.ToString();
            textBox1.Text = day + "/" + month + "/" + year;
            //this.groupBox1.Visible = false;
        }
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if (webBrowser1.Document != null)
            {
                htmlDoc = webBrowser1.Document;
                htmlDoc.Click += htmlDoc_Click;
            }
            tbsearchByName = textBox1;
            tbsearchByName.Click += tbsearchByName_Click;
            bttest = button1;
            bttest.Click += bttest_Click;
        }
        void htmlDoc_Click(object sender, HtmlElementEventArgs e)
        {
            if (monthCalendar1.Visible)
            {
                monthCalendar1.Visible = !monthCalendar1.Visible;
            }
            e.ReturnValue = false;
        }

        void tbsearchByName_Click(object sender, EventArgs e)
        {
            if (!monthCalendar1.Visible)
            {
                monthCalendar1.Visible = !monthCalendar1.Visible;
            }
        }

        void bttest_Click(object sender, EventArgs e)
        {
            HtmlElement date = webBrowser1.Document.GetElementById("txtReceiptCreadDate_dateInput");
            HtmlElement button = webBrowser1.Document.GetElementById("btnSearch");
            //string test = monthCalendar1.SelectionStart.Year.ToString()+"-"+monthCalendar1.SelectionStart.Month.ToString()+"-"+monthCalendar1.SelectionStart.Day.ToString()+"-00-00-00";
            //date.SetAttribute("value", "2013-03-19-00-00-00");
            //date.SetAttribute("value", test);
            //button.InvokeMember("click");
            //MessageBox.Show(test);
        }
    }
}